package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.annotation.LoginUser;
import io.renren.modules.app.dao.ImTagDao;
import io.renren.modules.app.entity.ImFriendEntity;
import io.renren.modules.app.entity.ImTagEntity;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.service.ImTagService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-05-23 08:46:57
 */
@RestController
@RequestMapping("app/imtag")
public class ImTagController {
    @Autowired
    private ImTagService imTagService;
    @Autowired
    private ImTagDao imTagDao;

    @Login
    @RequestMapping("/listAll")
    @ApiOperation("标签列表")
    public R listAll(@LoginUser UserEntity  user, @RequestBody ImTagEntity bean){
        List<ImTagEntity> tagList = imTagDao.selectList(new QueryWrapper<ImTagEntity>().eq("user_id",user.getUserId()));
        return R.ok(tagList);
    }
    @Login
    @RequestMapping("/read")
    @ApiOperation("标签用户列表")
    public R read(@LoginUser UserEntity  user, @RequestBody ImTagEntity bean){
        List<ImFriendEntity> list = imTagDao.read(bean.getId());
        return R.ok(list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:imtag:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = imTagService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:imtag:info")
    public R info(@PathVariable("id") Integer id){
		ImTagEntity imTag = imTagService.getById(id);

        return R.ok().put("imTag", imTag);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:imtag:save")
    public R save(@RequestBody ImTagEntity imTag){
		imTagService.save(imTag);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:imtag:update")
    public R update(@RequestBody ImTagEntity imTag){
		imTagService.updateById(imTag);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:imtag:delete")
    public R delete(@RequestBody Integer[] ids){
		imTagService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
